Page({
  data:{
    swiperArr:[
      "/images/banner/banner1.jpg",
      "/images/banner/banner2.jpg",
      "/images/banner/banner3.jpg",
      "/images/banner/banner4.jpg"
    ],
    leftId:'left0',
    leftActiveNum:0,
    rightId:'right0',
    // 右侧高度的数组
    heightArr:[],
    movieArr:[{
      id:0,
      title:"人气Top",
      subArr:[{
        imgSrc:"/images/menu/movie1.jpg",
        imgDesc:"周星驰"
      },{
        imgSrc:"/images/menu/movie2.jpg",
        imgDesc:"梁家辉"
      },{
        imgSrc:"/images/menu/movie3.jpg",
        imgDesc:"张家辉"
      }]
    },{
      id:1,
      title:"动作",
      subArr:[{
        imgSrc:"/images/menu/movie4.jpg",
        imgDesc:"吴京"
      },{
        imgSrc:"/images/menu/movie1.jpg",
        imgDesc:"周星驰"
      },{
        imgSrc:"/images/menu/movie2.jpg",
        imgDesc:"梁家辉"
      },{
        imgSrc:"/images/menu/movie3.jpg",
        imgDesc:"张家辉"
      }]
    },{
      id:2,
      title:"爱情",
      subArr:[{
        imgSrc:"/images/menu/movie1.jpg",
        imgDesc:"郭富城"
      }]
    },{
      id:3,
      title:"喜剧",
      subArr:[{
        imgSrc:"/images/menu/movie1.jpg",
        imgDesc:"沈腾"
      },{
        imgSrc:"/images/menu/movie2.jpg",
        imgDesc:"周润发"
      }]
    },{
      id:4,
      title:"战争",
      subArr:[{
        imgSrc:"/images/menu/movie4.jpg",
        imgDesc:"周笔畅"
      },{
        imgSrc:"/images/menu/movie4.jpg",
        imgDesc:"范冰冰"
      },{
        imgSrc:"/images/menu/movie2.jpg",
        imgDesc:"周润发"
      }]
    }]
  },
  // 获取每个区块的高度
  onReady(){
    let _this = this
    setTimeout(()=>{
      let initArr = [0]; //初始的数组
      let initNum = 0; //初始的数值
      const query = wx.createSelectorQuery()
      query.selectAll('.rightblock').boundingClientRect()
      query.selectViewport().scrollOffset()
      query.exec(function(res){
        res[0].map(item => {
          initNum += item.height //实现高度累加
          initArr.push(initNum) //将累加出来的高度push到数组中
        })
      console.log(initArr);
      _this.setData({
        heightArr:initArr
      })
      })
    },300)
  },
  // 左侧点击事件
  leftClickFn(e){
    // console.log( e.target.dataset.myid,this.data.heightArr);
    this.setData({
      leftId:'left'+ e.target.dataset.myid,
      leftActiveNum: e.target.dataset.myid,
      rightId:'right'+ e.target.dataset.myid,
    })
  },
  // 右侧滚动事件
  rightScrollFn(e){
  //  console.log(e);
   this.data.heightArr.forEach((item,index) => {
     if(e.detail.scrollTop > this.data.heightArr[index] && e.detail.scrollTop < this.data.heightArr[index + 1] - 5){
    //  console.log(item,index);
       if(this.data.leftActiveNum > index && e.detail.deltaY < 0){
        this.setData({
          leftId:'left'+ this.data.leftActiveNum,
          leftActiveNum: this.data.leftActiveNum,
         })
       }else{
        this.setData({
          leftId:'left'+ index,
          leftActiveNum: index,
         })
       }
       return;
     }
   })
  }
})